package com.cyc.gulimall.ssoclient.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Controller
public class HelloController {

    @ResponseBody
    @GetMapping("/hello")
    public String hello(){

        return "hello";
    }

    @GetMapping("/boss")
    public String employees(Model model, HttpSession session,@RequestParam(value = "token",required = false) String token){

        if (!StringUtils.isEmpty(token)){
            session.setAttribute("loginUser","lisi");
        }
        Object loginUser = session.getAttribute("loginUser");
        if (loginUser==null){


            return "redirect:http://localhost:8086/login.html?redirect_url=http://localhost:8084/boss";
        }else {
            List<String> emps=new ArrayList<>();
            emps.add("张三");
            emps.add("李四");
            model.addAttribute("emps",emps);
            return "employees";
        }

    }


}
